﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RPGProject.GameWorld;
using RPGProject.IOBuffers;
namespace RPGProject.LoopSystem
{
    class Visuals : Loop
    {
        private VisualType vType;
        public VisualType ToShow
        {
            get { return this.vType; }
            set { this.vType = value; }
        }
        private World world;
        private LogOutputBuffer openingScreen;
        private LogOutputBuffer helpScreen;
        private LogOutputBuffer loseScreen;
        private LogOutputBuffer winScreen;
        public Visuals(int width, int height, World w, LoopManager lm) : base(lm)
        {
            this.world = w;
            this.openingScreen = null;
            try
            {
                this.openingScreen = LogOutputBuffer.CreateLogFromFile("opening.txt", width, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("opening.txt failed to load.  Please recreate file.");
                Console.ReadKey();
                return;
            }
            this.helpScreen = null;
            try
            {

                this.helpScreen = LogOutputBuffer.CreateLogFromFile("help.txt", width, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("help.txt failed to load.  Please recreate file.");
                Console.ReadKey();
                return;
            }
            this.winScreen = null;
            try
            {
                this.winScreen = LogOutputBuffer.CreateLogFromFile("win.txt", width, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("win.txt failed to load.  Please recreate file.");
                Console.ReadKey();
            }
            this.loseScreen = null;
            try
            {
                this.loseScreen = LogOutputBuffer.CreateLogFromFile("lose.txt", width, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("lose.txt failed to load.  Please recreate file.");
                Console.ReadKey();
            }
        }
        
        public FuncType LoseScreen()
        {
            this.loseScreen.Render(true);
            Console.ReadKey();
            this.loopManager.ClearAllFuncs();
            return FuncType.REMOVE;
        }
        public FuncType HelpScreen()
        {
            this.helpScreen.Render();
            Console.ReadKey();
            this.loopManager.ClearAllFuncs();
            return FuncType.REMOVE;
        }
        public FuncType WinScreen()
        {
            this.winScreen.Render(true);
            Console.ReadKey();
            return FuncType.REMOVE;
        }
        public FuncType LogScreen()
        {
            this.world.RenderLog(true);
            Console.ReadKey();
            return FuncType.REMOVE;
        }
        public FuncType OpeningScreen()
        {
            this.openingScreen.Render();
            Console.ReadKey();
            return FuncType.REMOVE;
        }

        public override FuncType RunOnce()
        {
            switch (this.vType)
            {
                case VisualType.HELP:
                    return this.HelpScreen();
                case VisualType.LOSE:
                    return this.LoseScreen();
                case VisualType.WIN:
                    return this.WinScreen();
                case VisualType.LOG:
                    return this.LogScreen();
                case VisualType.OPEN:
                    return this.OpeningScreen();
            }

            return FuncType.REMOVE;
        }
    }
    public enum VisualType
    {
        WIN,
        LOSE,
        OPEN,
        LOG,
        HELP
    }
}
